using HKB.Common;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
namespace HKB.Web.DataHelper
{
	public class Shop_SepcBll
	{
		private Conn conn = null;
		public Shop_SepcBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public Shop_SepcBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetSepcAllCount()
		{
			return this.conn.GetDataTable("select * from HLShop_spec");
		}
		public DataTable GetSepcAll(int pageIndex, int pageSize)
		{
			string commandText = "select * from ( select *,ROW_NUMBER() over(order by sp_id) as number  from HLShop_spec ) t\r\n                                where t.number>(@CurrentPage-1)*@PageSize and t.number<=@CurrentPage*@PageSize ";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@PageSize", DbType.Int32, pageSize),
				this.conn.CreateParameter("@CurrentPage", DbType.Int32, pageIndex)
			};
			return this.conn.GetDataTable(commandText, parameters);
		}
		public bool GetDeleteSepc(int sp_id)
		{
			return this.conn.Execute("delete from HLShop_spec where sp_id=" + sp_id) == 1;
		}
		public object[] GetAddSpec(string sp_name, string sp_format, string sp_value, int sp_sort)
		{
			SqlParameter[] array = new SqlParameter[]
			{
				this.conn.CreateSQlParameter("@sp_name", SqlDbType.VarChar, sp_name, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@sp_format", SqlDbType.VarChar, sp_format, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@sp_value", SqlDbType.VarChar, sp_value, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@sp_sort", SqlDbType.Int, sp_sort, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Identity", SqlDbType.Int, 0, ParameterDirection.Output)
			};
			int num = this.conn.Execute("prc_CM_InserSpec", array);
			object[] result;
			if (num > 0)
			{
				result = new object[]
				{
					num,
					array[4].Value
				};
			}
			else
			{
				result = null;
			}
			return result;
		}
		public bool GetAddSpec_Value(string sp_value_name, int sp_id, string sp_value_image, int sp_value_sort)
		{
			string commandText = "INSERT INTO HLshop_spec_value(sp_value_name,sp_id,sp_value_image,sp_value_sort)VALUES(@sp_value_name,@sp_id,@sp_value_image,@sp_value_sort)";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@sp_value_name", DbType.String, sp_value_name),
				this.conn.CreateParameter("@sp_id", DbType.Int32, sp_id),
				this.conn.CreateParameter("@sp_value_image", DbType.String, sp_value_image),
				this.conn.CreateParameter("@sp_value_sort", DbType.Int32, sp_value_sort)
			};
			return this.conn.Execute(commandText, parameters) == 1;
		}
		public DataTable GetSpecBysp_id(int sp_id)
		{
			string sql = string.Concat(new object[]
			{
				"declare @sp_value varchar(max)\r\n                            set @sp_value=''\r\n                            select @sp_value=@sp_value+sp_value_name+',' from HLshop_spec_value where sp_id=",
				sp_id,
				" select *,@sp_value as sp_value from HLShop_spec where sp_id=",
				sp_id
			});
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetSpec_ValueBysp_id(int sp_id)
		{
			string sql = "select * from dbo.HLshop_spec_value where sp_id=" + sp_id;
			return this.conn.GetDataTable(sql);
		}
		public bool GetUpdateSpec(string sp_name, string sp_format, string sp_value, int sp_sort, int sp_id)
		{
			string commandText = "UPDATE HLShop_spec SET sp_name = @sp_name,sp_format = @sp_format,sp_value = @sp_value,sp_sort = @sp_sort WHERE sp_id=@sp_id";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@sp_name", DbType.String, sp_name),
				this.conn.CreateParameter("@sp_format", DbType.String, sp_format),
				this.conn.CreateParameter("@sp_value", DbType.String, sp_value),
				this.conn.CreateParameter("@sp_sort", DbType.Int32, sp_sort),
				this.conn.CreateParameter("@sp_id", DbType.Int32, sp_id)
			};
			return this.conn.Execute(commandText, parameters) == 1;
		}
		public bool GetUpdateSpec_value(string sp_value_name, int sp_id, string sp_value_image, int sp_value_sort, int sp_value_id)
		{
			string commandText = "UPDATE HLshop_spec_value SET sp_value_name = @sp_value_name,sp_id = @sp_id,sp_value_image = @sp_value_image,sp_value_sort = @sp_value_sort WHERE sp_value_id=@sp_value_id";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@sp_value_name", DbType.String, sp_value_name),
				this.conn.CreateParameter("@sp_id", DbType.Int32, sp_id),
				this.conn.CreateParameter("@sp_value_image", DbType.String, sp_value_image),
				this.conn.CreateParameter("@sp_value_sort", DbType.Int32, sp_value_sort),
				this.conn.CreateParameter("@sp_value_id", DbType.Int32, sp_value_id)
			};
			return this.conn.Execute(commandText, parameters) == 1;
		}
		public bool GetDeleteSpec(int sp_id)
		{
			return this.conn.Execute("delete from HLShop_spec where sp_id=" + sp_id) == 1;
		}
	}
}
